package com.zhq.dao;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.zhq.Interface.dao.IUserDao;
import com.zhq.entity.User;


public class UserDaoTest {
	private IUserDao userDao;
	private static ClassPathXmlApplicationContext ctx;
    @BeforeClass
    public static void setUpBeforeClass() throws Exception {
    	ctx = new ClassPathXmlApplicationContext(new String[]{"applicationContext.xml"});
    }
    
    
    @Before
    public void setUp() throws Exception {
    	userDao =(IUserDao)ctx.getBean("userDao");
    }
	
    //@Test
	public void testSaveUser() {
    	User user = new User();
    	user.setName("zhq");
    	user.setPassword("zhq");
    	userDao.saveUser(user);
    }
	
	
	@Test
	public void testFetchUserById() {
		assertEquals(2, userDao.fetchUserById(2).getId());
		System.out.println(userDao.fetchUserById(2).getId());
	}
	
	@Test
	public void testFetchUsers() {
		System.out.println(userDao.fetchUsers());
	}
}
